package com.tcc.etec.mecashow.activity;

import java.text.SimpleDateFormat;
import java.util.Locale;

import com.tcc.etec.mecashow.R;
import com.tcc.etec.mecashow.bdados.RecordeDao;
import com.tcc.etec.mecashow.objetos.Recorde;
import com.tcc.etec.mecashow.views.MecaTextView;

import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class RecordesActivity extends Activity{
	
	private ListView listView;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.recordes_layout);
		
		this.listView = (ListView) findViewById(R.id.records_list_view);
		this.listView.setAdapter(new ArrayAdapter<Recorde>(this, android.R.layout.simple_list_item_1, RecordeDao.getInstance(this).listarRecordes()){
			@Override
			public View getView(int position, View convertView, ViewGroup parent) {
				if(convertView == null){
					convertView = LayoutInflater.from(getContext()).inflate(R.layout.record_item, parent, false);
				}
				Recorde recorde = getItem(position);
				MecaTextView textViewNome = (MecaTextView) convertView.findViewById(R.id.record_item_nome);
				MecaTextView textViewData = (MecaTextView) convertView.findViewById(R.id.record_item_data);
				MecaTextView textViewPonto = (MecaTextView) convertView.findViewById(R.id.record_item_pontos);
				
				textViewNome.setText(recorde.getNomeJogador());
				SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm", Locale.getDefault());
				textViewData.setText(dateFormat.format(recorde.getData()));
				textViewPonto.setText(String.valueOf(recorde.getPontos()));
				return convertView;
			}
		});
		
		this.listView.addHeaderView(LayoutInflater.from(getApplicationContext()).inflate(R.layout.record_item, null));
	}
}
